package com.xnx.bincker.leader.service;

import com.xnx.bincker.leader.core.domain.BasicEntity;
import com.xnx.bincker.leader.core.repository.BasicRepository;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import java.io.Serializable;
import java.util.List;
import java.util.Optional;

/**
 * 基础服务类
 * @param <T> 对应实体
 * @param <S> 对应实体主键
 */
public interface BasicService<T extends BasicEntity, S extends Serializable> {
    void setBasicRepository(BasicRepository<T, S> repository);

	Optional<T> findById(S id);

	Optional<T> findOne(Example<T> example);

	T getOne(S id);

	List<T> findAll();

	List<T> findAll(Sort sort);

	Page<T> findAll(Pageable pageable);

	List<T> findAll(Example<T> example);

	List<T> findAll(Example<T> example, Sort sort);

	Page<T> findAll(Example<T> example, Pageable pageable);

	List<T> findAllById(Iterable<S> ids);

	long count();

	long count(Example<T> example);

	void delete(T t);

	void deleteById(S id);

	void deleteAll();

	void deleteInBatch(Iterable<T> objs);

	T save(T t);

	T saveAndFlush(T t);

    boolean exists(Example<T> t);

    boolean exists(S id);

	List<T> saveAll(Iterable<T> entities);

	void flush();
}
